FROM rust:latest

ENV RUSTUP_DIST_SERVER=https://rsproxy.cn
ENV RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup


# 安装特定版本的 Rust 工具链
RUN rustup install nightly-2022-08-08 && \
    rustup default nightly-2022-08-08 && \
    rustup component add rustfmt

# 创建必要的目录
RUN mkdir -p /root/.cargo

# 添加apt源配置和cargo配置
COPY sources.list /etc/apt/
COPY config /root/.cargo/

# 删除旧的 sources.list 文件
RUN rm -rf /etc/apt/sources.list.d/* && rm -f /etc/apt/sources.list

# 重新写入清华大学的镜像源
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm main contrib non-free" > /etc/apt/sources.list
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates main contrib non-free" >> /etc/apt/sources.list

# 更新软件包列表
RUN apt-get update
# 添加GPG密钥并安装软件
RUN DEBIAN_FRONTEND=noninteractive apt-get update -y && \
    apt-get install -y \
    llvm-16 \
    llvm-16-dev \
    libclang-16-dev \
    clang-16 \
    cmake \
    libssl-dev \
    pkg-config \
    bear \
    build-essential \
    python3 \
    python3-pip && \
    apt-get clean -y

# 添加requirements.txt并安装Python依赖
COPY requirements.txt /tmp/
RUN mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.bk
RUN pip3 install -r /tmp/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

CMD ["bash"]
